package com.wise.service.cms.content.listproduct;

import com.wise.entities.content.Product;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoPageList;
import com.wise.framework.restful.PageResultList;
import com.wise.summer.v1.cms.content.listproduct.PageListProduct;
import org.apache.commons.lang3.StringUtils;
import org.bouncycastle.asn1.isismtt.x509.ProcurationSyntax;
import org.springframework.stereotype.Service;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

/**
 * @author shaoming
 * @date 2019-09-11
 */
@Service
@SummerService
public class PageListProductService implements SummerServiceBean<PageListProduct> {

	@Override
	public void sum(PageListProduct summer) {
		if (summer.getCategoryType() == null) {
			summer.setCategoryType(0);
		}
		SqlSelect sqlSelect = SqlSelect.selec("*")
				.fromClassName(Product.class)
				.eq(Product._categoryType, summer.getCategoryType())
				.like(StringUtils.isNotBlank(summer.getName()), Product._name, "%" + summer.getName() + "%")
				.eq(StringUtils.isNotBlank(summer.getCategoryId()), Product._categoryId, summer.getCategoryId())
				.eq(null != summer.getState(), Product._state, summer.getState())
				.eqLang(Product._lang)
				.order_by(Product._sort)
				.order_by(Product._id + " desc");

		PageResultList<Product> productList = DaoPageList.s(Product.class, sqlSelect, summer.getStart(), summer.getLimit());

		summer.setSummerResult(productList);
	}

}
